/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;

import Action.ContactSessionBeanLocal;
import Entity.Contact;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Cyrax
 */
@ManagedBean
@SessionScoped
public class ContactBean {

    @EJB
    private ContactSessionBeanLocal contactSessionBean;
    private Contact con;
    private List<Contact> listcon;

    /** Creates a new instance of ContactBean */
    public ContactBean() {
    }

    /**
     * @return the con
     */
    public Contact getCon() {
        return con;
    }

    /**
     * @param con the con to set
     */
    public void setCon(Contact con) {
        this.con = con;
    }

    public List<Contact> getViewContact() {
        listcon = contactSessionBean.viewAllContact();
        return listcon;
    }

    public void deleteContact(Contact au) {
        contactSessionBean.deleteContact(au);
        //return "AboutUs.xhtml";
    }

    public void updateContact() {

        int Id = con.getCtID();
        contactSessionBean.updateContact(Id, con.getFirstName(), con.getYourEmail(), con.getMessage(), con.getCtDate(), con.getStatus());
    }

    public void addContact() {
        contactSessionBean.addContact(con);
    }
    private String key;

    public List<Contact> getsearchContact() {

//        if (searchType.equals("admin")) {

        listcon = contactSessionBean.searchContact(getKey().toString());

//        }

        return listcon;

    }

    /**
     * @return the key
     */
    public String getKey() {
        return key;
    }

    /**
     * @param key the key to set
     */
    public void setKey(String key) {
        this.key = key;
    }
}
